﻿using FlyHorse.LIMS.IBLL;
using FlyHorse.LIMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FlyHorse.LIMS.BLL
{
    public partial class RoleBll : BaseBll<Role>, IRoleBll
    {
        public int EditRoleResource(Role roleOld)
        {
            using (OJCB4Entities db = new OJCB4Entities())
            {
                List<Resource> resourcesList = new List<Resource>();
                foreach (var item in roleOld.Resources)
                {
                    resourcesList.Add(db.Resources.Find(item.ResourceID));
                }

                Role role = db.Roles.Find(roleOld.RoleID);
               // List<Resource> resList = role.Resources.ToList();
                var resList = role.Resources.ToList();
                resList.RemoveAll(m=>true);
                role.Resources = resourcesList;
                return db.SaveChanges();
            }
        }
    }
}
